package com.gxa.service.community.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.dto.communitydto.BuildingsDto;
import com.gxa.entity.community.Buildings;
import com.gxa.entity.community.Community;
import com.gxa.mapper.community.BuildingsMapper;
import com.gxa.service.community.BuildingsService;
import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-11 10:05:38
 */
@Service
public class BuildingsServiceImpl implements BuildingsService {

    @Autowired
    private BuildingsMapper buildingsMapper;

    @Override
    public List<Buildings> query(Integer pageNum, Integer pageSize) {
        return null;
    }

    @Override
    public List<Buildings> query() {
        return null;
    }

    @Override
    public Map<String, Object> queryAll(BuildingsDto buildingsDto, Integer pageNum, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();

        PageInfo<Buildings> pageInfo;
        try{
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            Page<Buildings> page = PageHelper.startPage(pageNum, pageSize);
            List<Buildings> buildingsList = buildingsMapper.queryAll(buildingsDto.getBuildNum(),buildingsDto.getBuildName());
            pageInfo = new PageInfo<>(buildingsList);
        }

//        QueryWrapper<Buildings> wrapper = new QueryWrapper<>();
//        wrapper.like("build_num",buildings.getBuildNum());
//        wrapper.like("build_name",buildings.getBuildName());
//        Page<Buildings> page = PageHelper.startPage(pageNum, pageSize);
//        List<Buildings> buildingsList = buildingsMapper.queryAll();
//        PageInfo<Buildings> pageInfo = new PageInfo<>(buildingsList);
        map.put("pageInfo",pageInfo);
        return map;
    }

    @Override
    public void add(Buildings buildings) {
        buildingsMapper.insert(buildings);
    }

    @Override
    public void deleteById(Integer id) {
        buildingsMapper.deleteById(id);
    }

    @Override
    public BuildingsDto queryById(Integer id) {
        BuildingsDto bdto = buildingsMapper.getById(id);
        return bdto;
    }

    @Override
    public void update(Buildings buildings) {
        buildingsMapper.updateById(buildings);
    }

    @Override
    public List<Buildings> queryByNum(String buildNum) {
        List<Buildings> buildingsList = buildingsMapper.queryByNum(buildNum);
        return buildingsList;
    }
}
